package ui.widget.card;

import ui.activity.card.CardListActivity;
import android.text.Editable;
import android.text.TextWatcher;

public class SearchKeyListener implements TextWatcher {

	private CardListActivity activity;
	
	public SearchKeyListener(CardListActivity activity) {
		super();
		this.activity = activity;
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count, int after) {

	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if (s.length() == 0) {
			this.activity.getService().listAllCard();
		} else {
			this.activity.getService().search(s.toString());
		}
		activity.getCardListAdapter().notifyDataSetChanged();
	}

	@Override
	public void afterTextChanged(Editable s) {

	}

}
